package com.rayboo.example.design.pattern.chain;

/**
 * 责任链模式
 * http://c.biancheng.net/view/1383.html
 */
public class Main {

    public static void main(String[] args) {
        Leader boss = new Boss(null);
        Leader manager = new Manager(boss);
        Leader director = new Director(manager);
        Leader grouper = new Grouper(director);
        Leader xiaoLi = new XiaoLi(grouper);

        // 小明上限 10 元
        printRequestState(xiaoLi.dispatchRequest(1));
        // 组长上限 100 元
        printRequestState(xiaoLi.dispatchRequest(12));
        // 主管上限 1000 元
        printRequestState(xiaoLi.dispatchRequest(230));
        // 经理上限 10000 元
        printRequestState(xiaoLi.dispatchRequest(3400));
        // 老板上限 100000 元
        printRequestState(xiaoLi.dispatchRequest(45000));

        System.out.println("--------");
        printRequestState(xiaoLi.dispatchRequest(560000));
    }

    private static void printRequestState(boolean isSuccess) {
        if (isSuccess) {
            System.out.println("* 小李报销成功");
        } else {
            System.out.println("* 没有人批复，小李报销失败");
        }
    }
}
